﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using PackTracker.Mobile.Properties;
using PackTracker.Mobile.Negocio;

namespace PackTracker.Mobile
{
    /// <summary>
    /// Configuration form to define WebServices URL, Data transfer interval and Vehicle identification.
    /// </summary>
    public partial class Config : Form
    {
        private Configuration configuration = null;

        /// <summary>
        /// Get all configurations and populate controls
        /// </summary>
        public Config()
        {
            InitializeComponent();

            configuration = new Configuration();

            txtWSAddress.Text   = configuration.GetConfig("WebServicesURL");
            txtInterval.Text    = configuration.GetConfig("Interval");
            txtVehicleID.Text   = configuration.GetConfig("VehicleID");
        }

        /// <summary>
        /// Discard changes and close form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cancelMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Save all configurations
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveMenuItem_Click(object sender, EventArgs e)
        {
            configuration.SetConfig("WebServicesURL", txtWSAddress.Text );
            configuration.SetConfig("Interval"      , txtInterval.Text  );
            configuration.SetConfig("VehicleID"     , txtVehicleID.Text );

            configuration.Dispose();

            this.Close();
        }
    }
}